import { _decorator, Component, Node ,Sprite ,SpriteFrame ,Button ,Label,Prefab,instantiate} from 'cc';
const { ccclass, property } = _decorator;

@ccclass('gameManager')
export class gameManager extends Component {
    @property(Node)
    jianbao: Node = null;

    @property(Node)
    Bg: Node = null;

    @property({ type: Node })
    contentNode: Node = null!; // 需要显示在圆角容器内的内容节点

    @property({ type: Prefab })
    listItem: Prefab = null!; // 获取预制体

    @property
    listItemNode: Node = null;

    @property({ type: Node })
    listGroup: Node = null!; // 预制体节点绑定的父节点

    @property(Node)
    yuanjiao: Node = null;

    angle_Speed: number = 50;///旋转速度

    angle: number = 0;


    start() {
        ////https://cdn.133.cn/ticket/vue/promotion/2025xhsquanyi/pyq1.png
        // this.bg.spriteFrame = '';
        // this.loadNetworkImage();
        //将预制体转为节点
        for (let i = 0; i < 30; i++) {
            // console.log(this.listItem);
            this.listItemNode = instantiate(this.listItem);
            let button:any = this.listItemNode.getComponent(Button);
            button.node.on('click',()=>{
                // alert(123);

                console.log('click:',i);
            }, this);
            this.listItemNode.children[0].children[0].getComponent(Label).string = 'boonookleft'+i.toString();
            this.listItemNode.children[0].children[1].getComponent(Label).string = 'boonookright'+i.toString();
            
            // console.log(this.listItemNode.children().getComponent(Label));
            //将节点添加到contentNode中
            this.listItemNode.parent = this.listGroup;
        }
        
    }

    onScrolling(scrollview, eventType, customEventData) {
        console.log('onScrolling:',scrollview, eventType, customEventData);
    }

    protected async onLoad() {
        // this.buyBtn.on(Button.EventType.CLICK,(event)=>{
        //     alert(231123)
        // }, this);
        // console.log(this.Bg.getComponent(Sprite));//spriteFrame
        // resources.load('https://cdn.133.cn/ticket/vue/promotion/2025xhsquanyi/pyq1.png',SpriteFrame, (err, texture) => { 
        //     if(err){
        //         console.log('err:',err);
        //         return;
        //     }
        //     this.Bg.getComponent(Sprite).spriteFrame = texture;
        // });
        
    }

    //  async loadNetworkImage() {
    //     try {
    //     let imageUrl = 'http://img.daimg.com/uploads/allimg/250504/3-250504224529.jpg';

    //     // 使用 fetch 获取图片
    //     const response = await fetch(imageUrl);
    //     const blob = await response.blob();
    //     const imgBitmap = await createImageBitmap(blob);
        
    //     // 创建 Texture2D
    //     const texture = new Texture2D();
    //     texture.uploadData(imgBitmap);

    //     // 创建 SpriteFrame
    //     const spriteFrame = new SpriteFrame();
    //     spriteFrame.texture = texture;
    //     this.Bg.getComponent(Sprite).spriteFrame = spriteFrame;
    //     } catch (error) {
    //         console.error('Error loading image:', error);
    //     }
    //  }

    update(deltaTime: number) {
        
    }
}


